home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / cd_bcn_h / cd_bcon.h
C/C++ Source or Header  |  1989-03-25  |  18KB  |  477 lines

  1. /**********************************************************************/
  2. /*            Low-Level I/O Routines with Carrier Detect              */
  3. /*                                                                    */
  4. /* By: Bryan D. Hall                                   Date: 03/15/89 */
  5. /* GEnie Address: BDHALL                                              */
  6. /* Fnet  Address: Bryan Hall, Node 227 CO (719)543-1869 12/24/96 HST  */
  7. /*                                        M-F 4PM-10AM, 24Hrs Weekends*/
  8. /*                                                                    */
  9. /**********************************************************************/
  10.  
  11.  
  12. /** cd_check() ********************************************************/
  13. /*   INPUT: None (hardware) CD Line                                   */
  14. /* PROCESS: This is a routine to check for carrier. Exits program if  */
  15. /*          no carrier                                                */
  16. /*  OUTPUT: None.  Exits with status 1                                */
  17. /**********************************************************************/
  18.  
  19. void cd_check()
  20. {
  21. char *gpip;
  22. long stack;
  23. char test;
  24.  
  25.    gpip=(char *)0xFFFFFA01L;
  26.    stack=Super(0L);
  27.    test= *gpip;    
  28.    Super(stack);
  29.    if (test & 2) 
  30.       exit(1); /* no carrier.. get out of this! */
  31. }
  32.  
  33.  
  34.  
  35. /** cd_bconin(int) ****************************************************/
  36. /*   INPUT: Device number. 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See    */
  37. /*          Bconin for more info.                                     */
  38. /* PROCESS: Same as for Bconin, but also checks for a carrier.        */
  39. /*  OUTPUT: See Bconin                                                */
  40. /**********************************************************************/
  41.  
  42. long cd_bconin(device)
  43. int device;
  44. {
  45. long temp;
  46.  
  47.      switch(device)
  48.           {
  49.           case 1:   /* AUX: set as primary device */
  50.                     cd_check();    /* first make sure there is a carrier */
  51.  
  52.                     temp = Bconstat(2); /* check console */
  53.  
  54.                     if (temp == -1)
  55.                          return(Bconin(2));  /* then get char from console */
  56.                     else
  57.                          return(Bconin(device));  /* then get char from device */
  58.                     break;
  59.  
  60.           case 2:   /* CON: set as primary device */
  61.                     return(Bconin(device));  /* then get char from console */
  62.                     break;
  63.  
  64.           case 3:   /* MIDI: set as primary device */
  65.                     temp = Bconstat(2); /* check console */
  66.  
  67.                     if (temp == -1)
  68.                          return(Bconin(2));  /* then get char from console */
  69.                     else
  70.                          return(Bconin(device));  /* then get char from device */
  71.                     break;
  72.           }
  73. }
  74.  
  75.  
  76.  
  77. /** cd_bconout(int,int) ***********************************************/
  78. /*   INPUT: (1) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. see*/
  79. /*          Bconout for more info.                                    */
  80. /*          (2) Character to output, in low byte.                     */
  81. /* PROCESS: Same as for Bconout, except checks for a carrier, and also*/
  82. /*          sends the character to the keyboard if aux: is selected.  */
  83. /*  OUTPUT: None                                                      */
  84. /**********************************************************************/
  85.  
  86. void cd_bconout(device,character)
  87. int device, character;
  88. {
  89.  
  90.      switch(device)
  91.           {
  92.           case 1:   /* aux: set as the primary device */
  93.                     cd_check();    /* first make sure there is a carrier */
  94.      
  95.                     Bconout(device,character); /* sent to device and console */
  96.                     Bconout(2,character);
  97.                     break;
  98.  
  99.           case 0:   /* Any other legal device */
  100.           case 2:
  101.           case 3:
  102.           case 4:
  103.           case 5:
  104.                     Bconout(device,character); /* send to device only */
  105.                     break;
  106.  
  107.           }
  108. }
  109.      
  110.  
  111. /** cd_bconstat(int) **************************************************/
  112. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See     */
  113. /*          Bconstat for more info.                                   */
  114. /* PROCESS: Same as for Bconstat, except checks for a carrier, and    */
  115. /*          also checks the keyboard if aux: is selected.             */
  116. /*  OUTPUT: Returns -1 if at least one character is ready, else 0     */
  117. /**********************************************************************/
  118.  
  119. long cd_bconstat(device)
  120. int device;
  121. {
  122. long temp;
  123.  
  124.      switch(device)
  125.           {
  126.           case 1:   /* AUX: set as primary device */
  127.                     cd_check();    /* first make sure there is a carrier */
  128.  
  129.                     temp = Bconstat(2); /* check console */
  130.  
  131.                     if (temp == -1)
  132.                          return(temp);  /* then send "console is ready" */
  133.                     else
  134.                          return(Bconstat(device)); /* otherwise check AUX: */
  135.                     break;
  136.  
  137.           case 0:   /* PRN:, CON:, or MIDI: */
  138.           case 2:
  139.           case 3:
  140.                     return(Bconstat(device));
  141.                     break;
  142.           }
  143. }
  144.  
  145.  
  146.  
  147. /** cd_bcostat(int) ***************************************************/
  148. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc.  See   */
  149. /*          Bcostat for more info.                                    */
  150. /* PROCESS: Same as for Bcostat, except it also checks for a carrier. */
  151. /*  OUTPUT: Returns -1 if device is ready, else 0.                    */
  152. /**********************************************************************/
  153.  
  154. long cd_bcostat(device)
  155. int device;
  156. {
  157.      switch(device)
  158.           {
  159.           case 1:   /* AUX: set as primary device */
  160.                     cd_check();    /* first make sure there is a carrier */
  161.                     return(Bcostat(device));
  162.                     break;
  163.  
  164.           case 0:   /* Any other legal device */
  165.           case 2:
  166.           case 3:
  167.           case 4:
  168.           case 5:
  169.                     return(Bcostat(device));
  170.                     break;
  171.           }
  172. }
  173.  
  174.  
  175. /** cd_getchar(int) ***************************************************/
  176. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See     */
  177. /*          Bcostat for more info                                     */
  178. /* PROCESS: Waits for a character from the specified device.  Then it */
  179. /*          checks to see if the chatacter is printable.  If so, it   */
  180. /*          is displayed and returned.  However, if the character is  */
  181. /*          a <CTRL-S>, the routine remembers this, and the next time */
  182. /*          called, will not echo the character, but will return it   */
  183. /*          and cancel the pause.                                     */
  184. /*          NOTE: If the device is not con:, it will also get the     */
  185. /*                from the keyboard.                                  */
  186. /*  OUTPUT: Returns the character, as an int.                         */
  187. /**********************************************************************/
  188.  
  189. int cd_getchar(device)
  190. int device;
  191. {
  192. long temp;
  193. static int paused;
  194.  
  195.      while (cd_bconstat(device) == 0)   /* wait for a character */
  196.           ;
  197.  
  198.      temp = cd_bconin(device);     /* get character */
  199.  
  200.      if ((isprint((int)temp) || ((int)temp == 10) || ((int)temp == 13)
  201.           || ((int)temp == 8)) && !paused )
  202.           {
  203.           cd_bconout(device,(int)temp);    /* echo out to device */
  204.           }
  205.      else
  206.           {
  207.           if ((int)temp == 19)  /* CTRL-S */
  208.                paused = 1;  /* set flag */
  209.           else
  210.                paused = 0; /* not paused */
  211.           }
  212.  
  213.  
  214.      return( (int)temp );     /* return ASCII code */
  215. }
  216.  
  217.  
  218. /** cd_hgetchar(int) **************************************************/
  219. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See     */
  220. /*          Bcostat for more info.                                    */
  221. /* PROCESS: Waits for a character from the specified device.  Does NOT*/
  222. /*          echo character to device or screen.                       */
  223. /*  OUTPUT: Returns the character as an int.                          */
  224. /**********************************************************************/
  225.  
  226. int cd_hgetchar(device) /* hidden get character (no echo) */
  227. int device;
  228. {
  229. long temp;
  230.  
  231.      while (cd_bconstat(device) == 0)   /* wait for a character */
  232.           ;
  233.  
  234.      temp = cd_bconin(device);     /* get character */
  235.  
  236.      return( (int)temp );     /* return ASCII code */
  237. }
  238.  
  239.  
  240. /** cd_putchar(char,int) **********************************************/
  241. /*   INPUT: (1) Character to output.                                  */
  242. /*          (2) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  243. /*          Bcostat for more info.                                    */
  244. /* PROCESS: Sends out a character to the specified device.  If the    */
  245. /*          character is a LineFeed, then it also sends a <CR>.       */
  246. /*          NOTE: If the device is not con:, it will also send the    */
  247. /*                char. to the screen.                                */
  248. /*  OUTPUT: None                                                      */
  249. /**********************************************************************/
  250.  
  251. void cd_putchar(inchar, device)
  252. char inchar;
  253. int device;
  254. {
  255.      cd_bconout(device, (int)inchar);   /* send out character */
  256.  
  257.      if (inchar == 10)    /* LF */
  258.           cd_bconout(device, 13);   /* send out CR */
  259.  
  260. }
  261.  
  262.  
  263. /** cd_gets(char,int,int) *********************************************/
  264. /*   INPUT: (1) "String" pointer.                                     */
  265. /*          (2) Maximum number of chars to get.                       */
  266. /*          (3) Device number 0=prn:, 1=aux:, 2=con:, or 3=MIDI.  See */
  267. /*          Bcostat for more info.                                    */
  268. /* PROCESS: Works somewhat like gets(), except that you can set the   */
  269. /*          maximum number of characters to be typed in, plus allows  */
  270. /*          for non-redirectable input.  It also sends out a <BELL>   */
  271. /*          character when a user tries to backspace past the         */
  272. /*          beginning of the line, and also after the last acceptable */
  273. /*          character space has been filled.  This allows the user to */
  274. /*          then backspace for corrections.                           */
  275. /*          NOTE: If the device is not con:, it will also get the     */
  276. /*                "string" from the keyboard.                         */
  277. /*  OUTPUT: None.                                                     */
  278. /**********************************************************************/
  279.  
  280. void cd_gets(s,n,device)
  281. char s[];
  282. int n,device;
  283. {
  284. register int c;
  285. int at_now=0;
  286. long temp;
  287.  
  288.     while(1)
  289.           {
  290.  
  291.           while (cd_bconstat(device) == 0)   /* wait for a character */
  292.                ;
  293.  
  294.           temp = cd_bconin(device);     /* get character */
  295.  
  296.           c = (int)temp;
  297.  
  298.           if (c == 8) /* BS */
  299.                {
  300.                if (at_now > 0)
  301.                     {
  302.                     n+=1;
  303.                     at_now-=1;
  304.                     
  305.                     cd_bconout(device,c);    /* echo out to device */
  306.                     }
  307.                else
  308.                     {
  309.                     cd_bconout(device,7); /* echo bell out to device */
  310.                     }                    
  311.                }
  312.           else
  313.                {
  314.                if ((isprint(c) || (c == 10) || (c == 13)
  315.                       || (c == 8)))
  316.                     {
  317.                     s[at_now++] = c;
  318.  
  319.                     if (!(n-2))
  320.                          {
  321.                          cd_bconout(device,7); /* echo bell out to device */
  322.                          }     
  323.                     
  324.                     if ((--n <= 0) || (c == 13) || (s[at_now-1] == '\n'))
  325.                          {
  326.                          s[at_now-1] = '\0';
  327.                          return;
  328.                          }
  329.  
  330.                     cd_bconout(device,c);    /* echo out to device */
  331.  
  332.                     }
  333.                }
  334.           }
  335. }
  336.  
  337.  
  338.  
  339. /** cd_puts(char,int) *************************************************/
  340. /*   INPUT: (1) Pointer to "string" to output.                        */
  341. /*          (2) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  342. /*          Bcostat for more info.                                    */
  343. /* PROCESS: Works just like puts() (except for re-direction           */
  344. /*          protection), plus adds the pause features found in the    */
  345. /*          cd_putchar routine.                                       */
  346. /*          NOTE: If the device is not con:, it will also send the    */
  347. /*                "string" to the screen.                             */
  348. /*  OUTPUT: None.                                                     */
  349. /**********************************************************************/
  350.  
  351. void cd_puts(s,device)
  352. char *s;
  353. int device;
  354. {
  355. int c;
  356.  
  357.      while (c = *s++)
  358.           cd_putchar(c, device);
  359. }
  360.  
  361.  
  362. /** cd_nputs(char,int,int) ********************************************/
  363. /*   INPUT: (1) Pointer to "string" to be output.                     */
  364. /*          (2) Maximum number of chars to output.                    */
  365. /*          (3) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  366. /*          Bcostat for more info                                     */
  367. /* PROCESS: Works just like cd_puts() but allows you to specify the   */
  368. /*          maximum number of characters to be output.                */
  369. /*          NOTE: If the device is not con:, it will also send the    */
  370. /*                "string" to the screen.                             */
  371. /*  OUTPUT: None.                                                     */
  372. /**********************************************************************/
  373.  
  374. void cd_nputs(s,n,device)
  375. char *s;
  376. int device,n;
  377. {
  378. int c;
  379.  
  380.      while ((c = *s++) && (--n))
  381.           cd_putchar(c, device);
  382. }
  383.  
  384.  
  385. /** clr_scrn(int) *****************************************************/
  386. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. see    */
  387. /*          Bcostat for more info                                     */
  388. /* PROCESS: Sends both a VT-52 clear screen & home cursor, and a <LF> */
  389. /*          to the device, and just the VT-52 code to con:            */
  390. /*  OUTPUT: None.                                                     */
  391. /**********************************************************************/
  392.  
  393. void clr_scrn(device)
  394. int device;
  395. {
  396.      cd_puts("\033E \f",device); /* clear screen */
  397.      cd_puts("\033E",2);
  398. }
  399.  
  400.  
  401. /** read_file(char,int) ***********************************************/
  402. /*   INPUT: (1) Pointer to file path\name. Exp: "c:\txt\read.me"      */ 
  403. /*          (2) Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc. See*/
  404. /*          Bcostat for more info                                     */
  405. /* PROCESS: Opens an ASCII (non-binary) file in read-only mode and    */
  406. /*          sends it one character at a time, to the device.  If a    */
  407. /*          <CTRL-S> is recieved (not echoed to device), it will pause*/
  408. /*          until any other character is received.  If <CTRL-C> is    */
  409. /*          recieved when not paused, it will close the file and      */
  410. /*          abort.  If the file cannot be opened, a message will be   */
  411. /*          displayed and the function will abort.                    */
  412. /*          NOTE: If the device is not con:, it will also send the    */
  413. /*                file to the screen.                                 */
  414. /*  OUTPUT: None.                                                     */
  415. /**********************************************************************/
  416.  
  417. void read_file(filename,device)
  418. char filename[];
  419. int device;
  420. {
  421. FILE *fp;
  422. int ch, stat;
  423. long temp=0L;
  424.  
  425.      if ((fp = fopen(filename,"r")) != NULL)
  426.           {
  427.           while (((ch = fgetc(fp)) != EOF) && (stat != 1))
  428.                {
  429.                cd_putchar(ch,device); /* send out char */
  430.  
  431.                if (cd_bconstat(device) == -1L) /* If true, char is availible*/
  432.                     {
  433.                     ch=cd_hgetchar(device);       /* Get input */
  434.  
  435.                     if (ch == 19) /* CTRL - S */
  436.                          {
  437.                          cd_hgetchar(device); /* wait for key */
  438.  
  439.                          stat = 0;
  440.                          }
  441.                     else if (ch == 3) /* CTRL - C */
  442.                          stat = 1;
  443.                     }
  444.                }
  445.           }
  446.      else
  447.           {
  448.           cd_puts("\nCannot open file: ", device);
  449.           cd_puts(filename, device);
  450.           return;
  451.           }
  452.  
  453.      fclose(fp);
  454. }
  455.  
  456.  
  457.  
  458. /** do_pushany(int) ***************************************************/
  459. /*   INPUT: Device number 0=prn:, 1=aux:, 2=con:, 3=MIDI, etc.  See   */
  460. /*          Bcostat for more info.                                    */
  461. /* PROCESS: Sends out a "Press any key message", then waits for a     */
  462. /*          character.                                                */
  463. /*          NOTE: If the device is not con:, it will also send the    */
  464. /*                message to the screen.                              */
  465. /*  OUTPUT: None.                                                     */
  466. /**********************************************************************/
  467.  
  468. void do_pushany(device)
  469. int device;
  470. {
  471.  
  472.      cd_puts("\n\t\t\t << Press ANY Key to Continue >>\n",device);
  473.  
  474.      cd_hgetchar(device);
  475. }
  476.  
  477.